import { defineConfig, loadEnv } from 'vite'
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver, } from 'unplugin-vue-components/resolvers'

const env = loadEnv('development', process.cwd());

export default defineConfig({
  plugins: [
    vue(),
    Components({
      dirs: [], // Avoid parsing src/components.  避免解析到src/components
      deep: false,
      resolvers: [AntDesignVueResolver({
        importStyle: false,
        resolveIcons: true,
      })],
    })
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, './src'),
      },
      {
        find: 'assets',
        replacement: resolve(__dirname, './src/assets'),
      },
      {
        find: 'vue',
        replacement: 'vue/dist/vue.esm-bundler.js', // compile template
      },
    ],
    extensions: ['.ts', '.js'],
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${resolve(
            'src/assets/style/breakpoint.less'
          )}";`,
        },
        javascriptEnabled: true,
      },
    },
  },
  server: {
    open: true,
    host: '0.0.0.0',
    fs: {
      strict: true,
    },
    proxy: {
      '/chat-api': {
        target: env.VITE_API_BASE_DOMAIN,
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace('/chat-api', '/chat-api'),
      },
    },
  },
})
